package hy;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyCtrl {
    @Autowired
    KafkaTemplate<String,String> tmp;
    @GetMapping("/send/{input}")
    @Transactional
    public String sendToKafka(@PathVariable String input){
        tmp.send("first",input+"_one");
        if("error".equals(input)){
            int i=1/0;
        }
        tmp.send("first",input+"two");
        return "send success";
    }

    //注解用于监听topic中数据的变量
    @KafkaListener(topics="first",groupId = "gr01")
    public void consumMsg(String msg){
        System.out.println("================"+msg+"==============");
    }
}